/// \file
#ifndef FILE_inode_H
#define FILE_inode_H

#include "globals.h"
#include "hdi.h"
#include "filesystemdata.h"
#include <time.h>

/*rw-r-----*/
#define FS_DEFAULT_RIGHTS (0640)

#define FS_INODE_STATIC_BLOCKS_COUNT 10

typedef blockid_t inodeid_t;
typedef int64_t filepos_t;

/// An inode references a file, wich may also be a folder.
///
/// The difference between them is only at high level.
typedef struct inode_t_{
	uint32_t refCount;
	uint8_t isFolder;
	/// \todo Add guid
	uint16_t rights;
	filepos_t fileSize;
	// Sorry, pal, not realy portable, but it will have to do.
	// It ain't even have a fixed size...
	time_t lastAccess;
	char _rep;
	blockid_t blocksfirsts[FS_INODE_STATIC_BLOCKS_COUNT];
	char _fi;
	blockid_t simpleIndirect;
	blockid_t doubleIndirect;
	blockid_t tripleIndirect;
	char _end;
}inode_t;

/// Create an inode, set adress and set the refcount to 1.
///
/// Does not create a  folder completely, it just sets the flag.
/// \param needAllocation whether address shall be booked or if
/// it already contains an allocated inode.
fs_ret_t fs_newInode(FileSystemHandle_t *fsh,inodeid_t* address, bool isFolder, bool needAllocation);

/// Delete all of a inode's blocks.
fs_ret_t fs_deleteFileBlocks(FileSystemHandle_t *fsh, inode_t *inode);

/// \todo An hard link creation function.

/// Remove 1 to the inode refCount, and delete it if refCount is 0.
fs_ret_t fs_removeInodeRef(FileSystemHandle_t *fsh,inodeid_t inodeAddress);

/// Fills inodeContent with the content of the given inode adress.
fs_ret_t fs_getInode(FileSystemHandle_t *fsh,inodeid_t address,inode_t* inodeContent);
/// \todo Set inode.

/// Prints the file info.
///
/// No additionnal data is given with folders.
fs_ret_t fs_d_printFileInfo(FileSystemHandle_t *fsh,inodeid_t address);


#endif // FILE_inode_H

